﻿using System;
using System.Configuration;
using System.Xml;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 控制台颜色枚举元素
    /// </summary>
    public sealed class ConsoleColorContentElement : EnumContentElement<ConsoleColor>
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ConsoleColorContentElement()
        {
            this.Value = ConsoleColor.White;
        }

        /// <summary>
        /// 反序列化配置信息
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="serializeCollectionKey"></param>
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            ConsoleColor color = ConsoleColor.White;
            if (reader != null)
            {
                object obj = reader.ReadElementContentAsString();
                if (obj != null)
                {
                    Enum.TryParse<ConsoleColor>(obj.ToString(), out color);
                }
            }
            this.Value = color;
        }        
    }
}
